<!-- head -->
{include file='public/head' /}
<!-- head -->

<!-- left -->
{include file='public/left' /}
<!-- left -->

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            管理后台
            <small>1.0.0</small>
        </h1>
        <ol class="breadcrumb">
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <!-- Info boxes -->
        <div class="row">
            <div class="col-sm-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">贷款问答回复</h3>
                    </div>
                    <!-- /.box-header -->
                    <form class="form-horizontal" id="form" action="{:url('admin/question/insertanswer','','')}">
                        <input type="hidden" id="question_id" value="{$row.id}">
                        <div class="box-body">
                            <div class="row" style="margin-bottom: 10px;">
                                <div class="col-sm-12">
                                    <p>{$row.question}</p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="content" class="col-sm-2 control-label">回答内容</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" id="content" name="content" placeholder="回答内容"></textarea>
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="text-align:right;">
                            <button type="button" class="btn btn-sm btn-default" id="resetForm">清空</button>&nbsp;
                            <button type="button" class="btn btn-sm btn-primary" id="saveForm">保存</button>
                        </div>
                    </form>
                    <!-- /.box-body -->
                    <div class="box-footer clearfix">
                    </div>
                    <!-- /.box-footer -->
                </div>
                <!-- /.box -->
            </div>
        </div>
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->

<script type="text/javascript">

    $(function(){

        $('#saveForm').click(function(){
            var question_id = $('#question_id').val();

            var content = $.trim($('#content').val());
            if (content == '') {
                $('#content').parents('.form-group').addClass('has-error');
                $('#content').parent().find('.help-block').html('请输入回答内容');
                return false;
            }

            $.ajax({
                url: $('#form').attr('action'),
                type: 'POST',
                data: {
                    'question_id': question_id,
                    'content': content,
                },
                dataType: 'JSON',
                success: function(data) {
                    if (data.status == 1) {
                        window.location.href = "{:url('admin/question/answer',['question_id'=>$row.id],'')}";
                    } else {
                        showAlert('提示', data.info, null);
                    }
                }
            });
        });

        $('#content').focus(function(){
            if ($('#content').parents('.form-group').hasClass('has-error')) {
                $('#content').parents('.form-group').removeClass('has-error');
                $('#content').parent().find('.help-block').html('');
            }
        });


    });

</script>

<!-- right -->
{include file='public/right' /}
<!-- right -->

<!-- foot -->
{include file='public/foot' /}
<!-- foot -->
